#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@File        :   704二分查找.py    
@Contact     :   lhouctcs@163.com
@License     :   MIT
@Time        :   2023/2/1 12:53
@Author      :   lhou 
@Version     :   0.1.0
@Description :   取值范围不同则处理函数完全不同！
"""
from typing import List


# import lib

class Solution:
    def search(self, nums: List[int], target: int) -> int:
        # 左闭右闭
        l, r = 0, len(nums) - 1
        while l <= r:
            mid = (r - l) // 2 + l
            if nums[mid] == target:
                return mid
            elif nums[mid] < target:
                l = mid + 1
            else:
                r = mid - 1
        return -1

    def search_2(self, nums: List[int], target: int) -> int:
        # 左闭右开
        l, r = 0, len(nums)
        while l < r:
            mid = (r - l) // 2 + l
            if nums[mid] == target:
                return mid
            elif nums[mid] < target:
                l = mid + 1
            else:
                r = mid
        return -1
